/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package services;

import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import modele.Semaine;
import modele.Ville;
import persistence.Villes;
import webservices.Google;
import webservices.LastFM;

/**
 *
 * @author Val
 */
public class Services {
    public static List<Ville> getVilles(){
        List<Ville> liste = null;
        try {
            liste = Villes.getVilles();
            if(liste.size() > 0) return liste;
            liste = LastFM.getVilles();

            for(Ville ville:liste) {
                String[] coords = Google.getCoords(ville.getNom(), ville.getPays());
                ville.setLat(coords[0]);
                ville.setLon(coords[1]);
                //Villes.insertAsync(ville);
                Villes.insertSync(ville);
                System.out.println(ville);
            }

            
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(Services.class.getName()).log(Level.SEVERE, null, ex);
        } catch (XPathExpressionException ex) {
            Logger.getLogger(Services.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Services.class.getName()).log(Level.SEVERE, null, ex);
        }

        return liste;
    }

    public static List<Semaine> getSemaines(){
        return null;
    }
}
